package com.example.administrator.myapplication.fragment;


import android.content.Intent;
import android.database.DatabaseUtils;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.activity.LoginActivity;
import com.example.administrator.myapplication.databinding.FragmentMySelfBinding;
import com.example.administrator.myapplication.myself.SQLiteActivity;
import com.example.administrator.myapplication.myself.SettingActivity;
import com.example.administrator.myapplication.until.CircleTransformation;
import com.squareup.picasso.Picasso;

/**
 * A simple {@link Fragment} subclass.
 */
public class MySelfFragment extends Fragment implements View.OnClickListener {
    private FragmentMySelfBinding binding;

    public static MySelfFragment newInstance(String nameNick, String img) {
        Bundle args = new Bundle();
        args.putString("nickName", nameNick);
        args.putString("img", img);
        MySelfFragment fragment = new MySelfFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public MySelfFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return DataBindingUtil.inflate(inflater, R.layout.fragment_my_self, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        String name = getArguments().getString("nickName");
        String img = getArguments().getString("img");
        if (name != null) {
            binding.fragmentMySelfLogin.setText(name);
            binding.fragmentMySelfLogin.setEnabled(false);
        }
        if (img != "") {
            Picasso.with(getContext()).load(img).transform(new CircleTransformation()).placeholder(R.mipmap.male_unchecked).into(binding.fragmentMySelfImg);
          binding.fragmentMySelfImg.setEnabled(false);
        }
        aboutBottomButton();
    }

    private void aboutBottomButton() {
        binding.fragmentMySelfB1.setOnClickListener(this);
        binding.fragmentMySelfB2.setOnClickListener(this);
        binding.fragmentMySelfBut1.setOnClickListener(this);
        binding.fragmentMySelfBut2.setOnClickListener(this);
        binding.fragmentMySelfBut3.setOnClickListener(this);
        binding.fragmentMySelfBut4.setOnClickListener(this);
        binding.fragmentMySelfLogin.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.fragment_mySelf_b1:
                intent.setClass(getContext(), SQLiteActivity.class);
                intent.putExtra("title", "我的关注");
                break;
            case R.id.fragment_mySelf_login:
                intent.setClass(getContext(), LoginActivity.class);
                break;
            case R.id.fragment_mySelf_b2:
                intent.setClass(getContext(), SQLiteActivity.class);
                intent.putExtra("title", "我的分享");
                break;
            case R.id.fragment_mySelf_but1:
                intent.setClass(getContext(), SQLiteActivity.class);
                intent.putExtra("title", "我的订阅");
                break;
            case R.id.fragment_mySelf_but2:
                intent.setClass(getContext(), SQLiteActivity.class);
                intent.putExtra("title", "播放历史");
            case R.id.fragment_mySelf_but3:
                intent.setClass(getContext(), SQLiteActivity.class);
                intent.putExtra("title", "我的分享");
                break;
            case R.id.fragment_mySelf_but4:
                intent.setClass(getContext(), SettingActivity.class);
                intent.putExtra("title", "我的设置");
                break;
        }
        startActivity(intent);
    }
}
